package com.chinaunicom.emergency.repository;

import com.chinaunicom.emergency.model.Dictionary;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * liliang
 * 2019-12-13
 */
@Repository
public interface DictionaryRepository extends JpaRepository<Dictionary,String>, JpaSpecificationExecutor {

    Dictionary findByParentIdAndDicCodeAndIsSoftDel(String parentId, String dicCode, Integer isSoftDel);

    Dictionary findByParentIdAndDicValueAndIsSoftDel(String parentId, String dicValue, Integer isSoftDel);

    Dictionary findByPidAndIsSoftDel(String PID, Integer isSoftDel);

    List<Dictionary> findByParentIdAndIsSoftDel(String rootId, int isSoftDel);

    @Query(nativeQuery = true, value = "select * from YJGL_DICTIONARY where IS_SOFT_dEL = ?2 AND PARENT_ID IN (select PID from YJGL_DICTIONARY where DIC_CODE = ?1 AND IS_SOFT_dEL = ?2 ) ")
    List<Dictionary> findListByParentDicCode(String dicCode, Integer isSoftDel);
    List<Dictionary> findAllByParentIdIsNull();

    Dictionary findByDicCodeAndIsSoftDel(String dicCode, Integer isSoftDel);
}
